package com.topInterview;

/**
 * @Author: huangzhigao
 * @Date: 2022/2/20 13:55
 */
public class Leecode48_rotatingImage {
    public void rotate(int[][] matrix) {
        //(tr,tc)左上角，(dr,dc)右下角
        int tr = 0;
        int tc = 0;
        int dr = matrix.length - 1;
        int dc = matrix[0].length - 1;
        while (tr < dr) {
            roateMaxtrix(matrix, tr++, tc++, dr--, dc--);
        }
    }

    public void roateMaxtrix(int[][] matrix, int tr, int tc, int dr, int dc) {
        //一共需要旋转多少组
        int times = dc - tc;
        for (int i = 0; i < times; i++) {
            int tmp = matrix[tr][tc+i];
            //左下角第一个数换到左上角第一个数
            matrix[tr][tc + i] = matrix[dr - i][tc];
            matrix[dr - i][tc] = matrix[dr][dc - i];
            matrix[dr][dc - i] = matrix[tr + i][dc];
            matrix[tr + i][dc] = tmp;
        }
    }
}
